package com.sltx.util.http;/*
package com.sltx.util.http;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.robin.util.MD5;
import com.sltx.dataobject.entity.LinkF;
import com.sltx.dataobject.entity.NodeF;
import org.apache.commons.lang.StringUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.robin.util.GsqlUtils;
import com.robin.util.TestGSQL;
public class CommonMethod {

	private static final Logger LOG = LoggerFactory.getLogger(CommonMethod.class);

*/
/**
	 * Gson 转化数据 并抛给页面
	 *
	 **//*


	public static void gson2Jsp(HttpServletResponse response,Object obj) {

		//转换数据类型
        GsonBuilder gbuilder = new GsonBuilder();
        // 去除对html格式的转化
     	Gson gson = gbuilder.disableHtmlEscaping().create();
		String jsonStr = gson.toJson(obj);
		//处理乱码问题
		response.setContentType("application/json; charset=utf-8");
		try {
			response.getWriter().write(jsonStr);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

*/
/**
	 * 根据value获取lcid
	 * 1.如果是中文，则去除括弧然后MD5
	 * 2.如果不是中文，则表示就是lcid，，不做任何处理
	 **//*


	public static String getLcidByValue(String v){
		String lcid = "";
		//正则表达式判断是否有中文
		String regexStr = "[\u4E00-\u9FA5]";
		Pattern pattern = Pattern.compile(regexStr);
	    Matcher matcher = pattern.matcher(v);

		if(matcher.find()){
			//去除中文括弧
			v = v.replaceAll("（", "").replaceAll("）", "");
			v = v.replaceAll("\\(", "").replaceAll("\\)", "");
			//对企业名称进行MD5，取得lcid
			try {
				lcid = MD5.GetMD5Code(v).toUpperCase();
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else{
			lcid = v;
		}
		return lcid;
	}

*/
/**
	 *GSQL查询及返回
	 * @throws JSONException
	 **//*


	@SuppressWarnings("unchecked")
	public static void proGSQL(String query,String typeIds,String attIds,Integer level,Map<String,Object> mapRes) throws JSONException{
		JSONObject jsonObject = TestGSQL.getData(query);
		if(jsonObject!=null){
			//节点
			JSONArray jsonArray = jsonObject.getJSONArray("entities");
			List<NodeF> listNodes = new ArrayList<NodeF>();
			NodeF nf = null;
			for(int i=0;i<jsonArray.length();i++){
				nf = new NodeF();
				JSONObject jsonObject2 = (JSONObject)jsonArray.opt(i);

				String nodeId = jsonObject2.getString("vertex id");
				String nodeType = jsonObject2.getString("vertex type");
				String extendNumber = jsonObject2.getString("extend number");
				String nodeName =null;
				JSONObject jAttr = jsonObject2.getJSONObject("attributes");
				Map<String, Object> mapAttr = CommonUtils.parserToMap(jAttr);
//				Map<String, Object>) mapAttr
				mapAttr.put("extendNumber", extendNumber);
				nf.setAttibuteMap(mapAttr);
				if("Person".equals(nodeType)){
					nodeType = "GR";
					nodeName = jAttr.getString("name");
				}else if("Enterprise".equals(nodeType)){
					nodeType = "GS";
					nodeName = jAttr.getString("business_name");
				}else if("Bidding".equals(nodeType)){
					nodeType = "GB";
					nodeName = jAttr.getString("title");
				}
				nf.setId(nodeId);
				nf.setType(nodeType);
				nf.setName(nodeName);
				listNodes.add(nf);
			}
			//关系
			JSONArray jsonArrayR = jsonObject.getJSONArray("relations");
//			List<Map<String,Object>> listRes = new ArrayList<Map<String,Object>>();
			List<LinkF> listRes = new ArrayList<LinkF>();
			LinkF link = null;
			for(int i=0;i<jsonArrayR.length();i++){
				link = new LinkF();
				JSONObject jsonObject2 = (JSONObject)jsonArrayR.opt(i);

				String from = jsonObject2.getString("start vetex id");
				String to = jsonObject2.getString("end vertex id");
				String type = jsonObject2.getString("edge type");
				String id = jsonObject2.getString("edge id");//
//				String id = jsonObject2.getString("edge id");//
				JSONObject jAttr = jsonObject2.getJSONObject("attributes");
				Map<?,?> mapAttr = CommonUtils.parserToMap(jAttr);
 				String name = getNameByType(type,link,mapAttr);
				if(StringUtils.isNotEmpty(type) && type.contains("INV")){
					String tmp = from;
					from = to;
					to = tmp;
					type = type.substring(5);
				}
				//多任职处理
				String position = (String) mapAttr.get("title");
				if(StringUtils.isNotEmpty(position)){
					type+=position;
				}
//				link.setId(id);
				link.setId(from+type+to);
				link.setName(name);
				link.setFrom(from);
				link.setSource(from);
				link.setTo(to);
				link.setTarget(to);
				listRes.add(link);
			}

			mapRes.put("nodes", listNodes);
			mapRes.put("links", listRes);
		}

	}


*/
/*
*
	 * 跟据类型获取边关系名称
	 * 根据关系处理不通类型的属性
	 * @param param 边名称
	 * @param mapRela 出参
	 * @param mapAttr 入参
	 * @return
*//*



	public static String getNameByType(String param,LinkF link,Map<?,?> mapAttr){
		String res = "";
		if(StringUtils.isNotEmpty(param)){
			Map<String, Object> attibuteMap = new HashMap<String, Object>();
			if(param.contains("Serve")){//任职关系
				res = "任职";
				String position = (String) mapAttr.get("title");
				attibuteMap.put("position", position);
			}else if(param.contains("Invest")){//投资关系
				res = "投资";
				String inv_rate = (String) mapAttr.get("investment_proportion");
				attibuteMap.put("inv_rate", inv_rate);
			}else if(param.contains("Branch")){//分支关系
				res = "分支";
			}else if(param.contains("Win")){//中标关系
				res = "中标";
			}
			link.setAttibuteMap(attibuteMap);
		}
		return res;
	}

*/
/**族谱查询
	 * @param mapReq
	 * @param mapRes*//*



	@SuppressWarnings("unchecked")
	public static void proGsqlData(Map<String,Object> mapReq,Map<String,Object> mapRes){
		//获取参数
		String value = (String) mapReq.get("value");
		String attIds = (String) mapReq.get("attIds");
		Integer level = Integer.parseInt(mapReq.get("level").toString());
		String nodeType = (String) mapReq.get("nodeType");
		String extend = (String) mapReq.get("extend");

		//参数校验
		if(!StringUtils.isNotEmpty(value) ||!StringUtils.isNotEmpty(attIds) || !StringUtils.isNotEmpty(extend)|| !StringUtils.isNotEmpty(nodeType) ){
			return;
		}
		if(level<=0 || level>3){
			return;
		}
		//拼装查询串
		String queryJ = "keyword:\""+value+"\", extend:\""+extend+"\", attIds:\""+attIds+"\",level:\""+level+"\",nodeType:\""+nodeType+"\"";
		//入参方法名称，查询串，返回json数据结果
		JSONObject jsonObject = IPlatformUtils.getInterPlatData(queryJ,"getEntGraphG");
		//打印返回json
//		if(jsonObject!=null){
//			LOG.info("接口平台返回数据："+jsonObject.toString());
//		}
		//统一处理结果
		proJsonData(jsonObject, mapRes);
	}

*/
/**
	 * 关联探寻
	 * @param mapReq
	 * @param mapRes*//*



	@SuppressWarnings("unchecked")
	public static void proGsqlRelatData(Map<String,Object> mapReq,Map<String,Object> mapRes){
		//获取参数
		String value = (String) mapReq.get("value");
		String attIds = (String) mapReq.get("attIds");
		Integer level = Integer.parseInt(mapReq.get("level").toString());
//		String nodeType = (String) mapReq.get("nodeType");
		String extend = "1";

		//参数校验
		if(!StringUtils.isNotEmpty(value) ||!StringUtils.isNotEmpty(attIds)){
			return;
		}
		if(level<=0 || level>10){
			return;
		}
		//拼装查询串
//		String queryJ = "entName:\""+value+"\", extend:\""+extend+"\", attIds:\""+attIds+"\",level:\""+level+"\"";
		String queryJ = "entName:\""+value+"\",  attIds:\""+attIds+"\",level:\""+level+"\"";
		//入参方法名称，查询串，返回json数据结果
//		JSONObject jsonObject = IPlatformUtils.getInterPlatData(queryJ,"getEntsRelevanceSeekGraphG");
		JSONObject jsonObject = IPlatformUtils.getInterPlatData(queryJ,"getEntGraphGShortData");
		//打印返回json
		LOG.info("接口平台返回数据："+jsonObject.toString());
		//统一处理结果
		handleJsonData(jsonObject, mapRes);
	}

*/
/**
	 * 企业list查询
	 * @param ent
	 * @return*//*



	public static List<String> getEnterpriseList(String keyword){
    	List<String> listENT = new ArrayList<String>();

    	//拼装查询串
		String queryJ = "keyword:\""+keyword+"\",  type:\"0\"";
		//入参方法名称，查询串，返回json数据结果
		JSONObject jsonObject = IPlatformUtils.getInterPlatData(queryJ,"getEntByKeyword");

    	try {
			if(jsonObject!=null){
				JSONArray jArr = jsonObject.getJSONArray("RESULTDATA");
				if(jArr!=null){
					for(int i=0;i<jArr.length();i++){
						JSONObject ent = (JSONObject) jArr.opt(i);
						String entName = (String) ent.get("ENTNAME");
						listENT.add(entName);
					}
				}
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return listENT;
    }

*/
/**
	 * 统一处理json数据*//*



	@SuppressWarnings("unchecked")
	public static void proJsonData(JSONObject jsonObject,Map<String,Object> mapRes){
		if(jsonObject!=null){
//			JSONObject jsonO = new JSONObject(jsonObject);
			try {
				JSONObject JsonR = jsonObject.getJSONObject("RESULTDATA");
				if(JsonR==null){
					return;
				}
				//节点
				JSONArray jsonArray = JsonR.getJSONArray("NODES");
				List<NodeF> listNodes = new ArrayList<NodeF>();
				NodeF nf = null;
				for(int i=0;i<jsonArray.length();i++){
					nf = new NodeF();
					JSONObject jsonObject2 = (JSONObject)jsonArray.opt(i);
					JSONObject jAttr = jsonObject2.getJSONObject("ATTIBUTEMAP");
					Map<String, Object> mapAttr = CommonUtils.parserToMap(jAttr);
					nf.setAttibuteMap(mapAttr);
					nf.setId(jsonObject2.getString("ID"));
					nf.setType(jsonObject2.getString("TYPE"));
					nf.setName(jsonObject2.getString("NAME"));
					listNodes.add(nf);
				}
				//关系
				JSONArray jsonArrayR = JsonR.getJSONArray("LINKS");
				List<LinkF> listRes = new ArrayList<LinkF>();
				LinkF link = null;
				for(int i=0;i<jsonArrayR.length();i++){
					link = new LinkF();
					JSONObject jsonObject2 = (JSONObject)jsonArrayR.opt(i);
					link.setId(jsonObject2.getString("ID"));
					link.setName(jsonObject2.getString("NAME"));
					link.setFrom(jsonObject2.getString("FROM"));
					link.setSource(jsonObject2.getString("FROM"));
					link.setTo(jsonObject2.getString("TO"));
					link.setTarget(jsonObject2.getString("TO"));
					Map<String,Object> attMap = CommonUtils.parserToMap(jsonObject2.getJSONObject("ATTIBUTEMAP"));
					link.setAttibuteMap(attMap);
					listRes.add(link);
				}
				mapRes.put("nodes", listNodes);
				mapRes.put("links", listRes);
			} catch (Exception e) {
				// TODO: handle exception
			}

		}
	}

*/
/**校验企业是否存在
	 * @param keyword
	 * @return*//*



	public static boolean checkEnterprise(String keyword){
    	List<String> listENT = new ArrayList<String>();

    	//拼装查询串
		String queryJ = "entName:\""+keyword+"\"";
		//入参方法名称，查询串，返回json数据结果
		JSONObject jsonObject = IPlatformUtils.getInterPlatData(queryJ,"getRegisterInfo");

    	try {
			if(jsonObject!=null){
				JSONArray jArr = jsonObject.getJSONArray("RESULTDATA");
				if(jArr!=null && jArr.length()>0){
					return true;
				}
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return false;
    }

*/
/**
	 * 主体基本信息查询
	 * @param ent
	 * @return*//*



	public static Map<String,Object> getEnterRegisterInfo(String entName,int type){
		Map<String,Object> allData = new HashMap<String,Object>();

    	//拼装查询串
		String queryJ = "keyword:\""+entName+"\",  type:\"0\"";
		if(type == 1){
			//基本信息
			JSONObject entInfo = IPlatformUtils.getInterPlatData(queryJ,"getEntByKeyword");
			allData.put("entInfo",CommonUtils.proAllJsonData(entInfo,type));
		}else if(type == 2){
			queryJ = "entName:\""+entName+"\"";
			//主体基本信息
			JSONObject registerInfo = IPlatformUtils.getInterPlatData(queryJ,"getRegisterInfo");
			allData.put("registerInfo",CommonUtils.proJsonData(registerInfo,type));
		}else if(type == 3){
			queryJ = "entName:\""+entName+"\"";
			//股东及出资信息
			JSONObject shareHolderInfo = IPlatformUtils.getInterPlatData(queryJ,"getShareHolderInfo");
			allData.put("shareHolderInfo",CommonUtils.proAllJsonData(shareHolderInfo,type));
		}else if(type == 4){
			queryJ = "entName:\""+entName+"\"";
			//主体对外投资
			JSONObject investmentAbroadInfo = IPlatformUtils.getInterPlatData(queryJ,"getInvestmentAbroadInfo");
			allData.put("investmentAbroadInfo",CommonUtils.proAllJsonData(investmentAbroadInfo,type));
		}else if(type == 5){
			queryJ = "entName:\""+entName+"\"";
			//主体分支机构
			JSONObject branchInfo = IPlatformUtils.getInterPlatData(queryJ,"getBranchInfo");
			allData.put("branchInfo",CommonUtils.proAllJsonData(branchInfo,type));
		}else if(type == 6){
			queryJ = "entName:\""+entName+"\"";
			//主要管理人员
			JSONObject mainManagerInfo = IPlatformUtils.getInterPlatData(queryJ,"getMainManagerInfo");
			allData.put("mainManagerInfo",CommonUtils.proAllJsonData(mainManagerInfo,type));
		}else{
			queryJ = "entName:\""+entName+"\",  pageStartRow:\"0\",pageEndRow:\"15\"";
			//专利信息
			JSONObject patentInfo = IPlatformUtils.getInterPlatData(queryJ,"getPatentInfo");
			allData.put("patentInfo",CommonUtils.proAllJsonData(patentInfo,type));
		}
    	return allData;
    }

	public static int findData(List<NodeF> list,String id){
		int n = 0;
		for(int i=0;i < list.size();i++){
			if(id.equals(list.get(i).getId())){
				n = i;
				break;
			}
		}
		return n;
	}

*/
/**
	 * 处理json数据*//*



	@SuppressWarnings("unchecked")
	public static void handleJsonData(JSONObject jsonObject,Map<String,Object> mapRes){
		if(jsonObject!=null){
			List<String> listRelation = new ArrayList<String>();
			try {
				JSONObject JsonR = jsonObject.getJSONObject("RESULTDATA");
				if(JsonR==null){
					return;
				}
				//节点
				JSONArray jsonArray = JsonR.getJSONArray("NODES");
				List<NodeF> listNodes = new ArrayList<NodeF>();
				NodeF nf = null;
				for(int i=0;i<jsonArray.length();i++){
					nf = new NodeF();
					JSONObject jsonObject2 = (JSONObject)jsonArray.opt(i);
					JSONObject jAttr = jsonObject2.getJSONObject("ATTIBUTEMAP");
					Map<String, Object> mapAttr = CommonUtils.parserToMap(jAttr);
					nf.setAttibuteMap(mapAttr);
					nf.setId(jsonObject2.getString("ID"));
					nf.setType(jsonObject2.getString("TYPE"));
					nf.setName(jsonObject2.getString("NAME"));
					listNodes.add(nf);
				}
				//关系
				JSONArray jsonArrayR = JsonR.getJSONArray("LINKS");
				List<LinkF> listRes = new ArrayList<LinkF>();
				LinkF link = null;
				String fromName = "";
				String toName = "";
				StringBuffer sf = new StringBuffer();
				for(int i=0;i<jsonArrayR.length();i++){
					link = new LinkF();
					JSONObject jsonObject2 = (JSONObject)jsonArrayR.opt(i);
					link.setId(jsonObject2.getString("ID"));
					link.setName(jsonObject2.getString("NAME"));
					link.setFrom(jsonObject2.getString("FROM"));
					int n1 = findData(listNodes,link.getFrom());
					if(n1 != -1){
						NodeF node1 = listNodes.get(n1);
						fromName = node1.getName();
					}
					link.setSource(jsonObject2.getString("FROM"));
					link.setTo(jsonObject2.getString("TO"));
					int n2 = findData(listNodes,link.getTo());
					if(n2 != -1){
						NodeF node2 = listNodes.get(n2);
						toName = node2.getName();
					}
					if("投资".equals(link.getName())){
						sf.append(fromName);
						sf.append("投资了");
						sf.append(toName);
					}
					if("任职".equals(link.getName())){
						sf.append(fromName);
						sf.append("在");
						sf.append(toName);
						sf.append("任职");
					}
					if(!"".equals(sf.toString())){
						listRelation.add(sf.toString());
					}
					link.setTarget(jsonObject2.getString("TO"));
					Map<String,Object> attMap = CommonUtils.parserToMap(jsonObject2.getJSONObject("ATTIBUTEMAP"));
					link.setAttibuteMap(attMap);
					listRes.add(link);

				}
				mapRes.put("nodes", listNodes);
				mapRes.put("links", listRes);
				mapRes.put("listRelation", listRelation);
			} catch (Exception e) {
				// TODO: handle exception
			}

		}
	}
}
*/
